import json
import os
import re


def _clean_json(string):
  string = re.sub(",[ \t\r\n]+}", "}", string)
  string = re.sub(",[ \t\r\n]+\]", "]", string)
  return string


def read_json(filename):
  ret = None
  if filename is not None and os.path.exists(filename):
    with open(filename, 'r') as f:
      ret = json.loads(_clean_json(f.read()))
  return ret
